package tests;

import org.junit.Test;

import changeEmployeeTransaction.changeAffiliationTransaction.ChangeMemberTransaction;
import changeEmployeeTransaction.changeAffiliationTransaction.ChangeUnaffiliatedTransaction;

import database.InMemoryPayrollDatabase;
import database.PayrollDatabase;
import addEmployeeTransaction.AddHourlyEmployee;
import addEmployeeTransaction.Employee;
import affiliation.Affiliation;
import affiliation.NoAffiliation;
import static org.junit.Assert.*;

public class TestChangeUnaffiliatedMember {
	PayrollDatabase database = InMemoryPayrollDatabase.getInstance();

	@Test
	public void testChangeUnaffiliatedMember() {
		int empId = 10;
		AddHourlyEmployee t = new AddHourlyEmployee(empId, "Bill", "Home",
				15.25, database);
		t.execute();
		int memberId = 7743;
		new ChangeMemberTransaction(empId, memberId, 99.42, database).execute();
		ChangeUnaffiliatedTransaction cut = new ChangeUnaffiliatedTransaction(
				empId, database);
		cut.execute();
		Employee e = database.getEmployee(empId);
		assertNotNull(e);
		Affiliation affiliation = e.getAffiliation();
		assertNotNull(affiliation);
		assertTrue(affiliation instanceof NoAffiliation);
		Employee member = database.getUnionMember(memberId);
		assertNull(member);
	}
}
